package com.gitee.huxing.course.core.datasource;

/**
 * @Description: 数据源的上下文切换管理
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.core.datasource
 * @ClassName: DataSourceContextHolder
 * @Author: huxing
 * @DateTime: 2021-09-16 上午10:58
 */
public class DataSourceContextHolder {

    private static final ThreadLocal<String> contextHolder = new InheritableThreadLocal<>();

    /**
     * @Description: 设置数据源
     * @Author: huxing
     * @Date: 2021-05-22 19:06
     * @param dataSource: 设置当前使用的数据源
     **/
    public static void setDataSource(String dataSource){
        contextHolder.set(dataSource);
    }

    /**
     * @Description: 获取数据源
     * @Author: huxing
     * @Date: 2021-05-22 19:06
     * @return: java.lang.String
     **/
    public static String getDataSource(){
        return contextHolder.get();
    }

    /**
     * @Description: 清除上下文
     * @Author: huxing
     * @Date: 2021-05-22 19:06
     * @return: void
     **/
    public static void clear(){
        contextHolder.remove();
    }
}
